<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <table cellspacing="0" border="1" width="600px">
        <thead>
            <tr>
                <td width="20%">
                    <input type="checkbox" class="selectAll">全选
                    <input type="checkbox" class="selectOther">反选
                </td>
                <td>姓名</td>
                <td>性别</td>
                <td>年龄</td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><input type="checkbox" class="user" /></td>
                <td>张三</td>
                <td>男</td>
                <td>28</td>
            </tr>
            <tr>
                <td><input type="checkbox" class="user" /></td>
                <td>李四</td>
                <td>女</td>
                <td>18</td>
            </tr>
            <tr>
                <td><input type="checkbox" class="user" /></td>
                <td>王八</td>
                <td>男</td>
                <td>45</td>
            </tr>
        </tbody>
    </table>
    <script>
        let allBtn = document.querySelector('.selectAll')
        let otherBtn = document.querySelector('.selectOther')
        let itmes = document.querySelectorAll('.user')

        itmes.forEach(v => {
            v.onclick = () => {
                let count = 0;
                itmes.forEach(v => {
                    if (v.checked === true)
                        count++;
                });
                allBtn.checked = count === itmes.length;
            }
        });

        allBtn.onclick = () => {
            itmes.forEach(v => {
                v.checked = allBtn.checked ? true : false
            });
        }

        otherBtn.onclick = () => {
            itmes.forEach(v => {
                v.checked = v.checked ? false : true
            });
        }
    </script>
</body>

</html>